/**
 * COPYRIGHT. Harry Wu 2011. ALL RIGHTS RESERVED.
 * Project: just
 * Author: Harry Wu <harrywu304@gmail.com>
 * Created On: Jun 22, 2011 9:07:12 AM
 *
*/ 
package org.justframework.plugin.http;

import org.justframework.server.ServerConnector;
import org.mortbay.jetty.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * http server connector
 *
 */
public class HttpServer implements ServerConnector{
	
	/**
	 * logger
	 */
	private static Logger logger = LoggerFactory.getLogger(HttpServer.class);
	
	private int port;
	
	/**
	 * jetty http server
	 */
	private Server server;

	public void startup() {
		try {				
			server = new Server(port);
			server.setHandler(new HttpHandlerAdapter());
			server.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void shutdown() {
		try {
			server.destroy();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/* (non-Javadoc)
	 * @see org.justframework.core.ServerConnector#getPort()
	 */
	public int getPort() {
		return port;
	}

	/* (non-Javadoc)
	 * @see org.justframework.core.ServerConnector#setPort(int)
	 */
	public void setPort(int port) {
		this.port = port;
	}
	
}
